package org.colafries.admin.querybuilder.entity;

import lombok.EqualsAndHashCode;
import org.colafries.admin.entity.vo.ColumnRspVO;
import org.colafries.admin.entity.domain.QueryParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author colafries
 * @version v1.0
 * @ClassName SqlContext
 * @Description SQL生成上下文
 * @date Created in 2024/5/15
 **/
@EqualsAndHashCode(callSuper = true)
@Data
public class CustomQuerySqlBuildContext extends SqlBuildContext {
    @ApiModelProperty(value = "query 结果列")
    private List<QueryParam.ResultColumn> resultColumns = new ArrayList<>();

    @ApiModelProperty(value = "自定义表Map")
    private Map<String, ColumnRspVO> customTableSchemaMap = new HashMap<>();

    @ApiModelProperty(value = "列表达式Map")
    private Map<String, String> columnExpressionMap = new HashMap<>();

    public Map<String, String> getFildExpMap() {
        return customTableSchemaMap.entrySet().stream()
                .collect(Collectors.toMap(
                        Map.Entry::getKey,
                        entry -> String.format("`%s`.`%s`", entry.getValue().getTableHash(), entry.getValue().getField())
                ));
    }
}